import axios from 'axios'

/* 全局错误提示 引入 */
import { Message } from 'element-ui'

const http = axios.create({
  baseURL: 'http://127.0.0.1:8888/api/private/v1/'
})

/* axios请求拦截 */
http.interceptors.request.use(config => {

  /* 设置请求头传递token,验证 */
  const token = localStorage.token
  if (token) {
    config.headers.Authorization = token
  }
  return config
}, err => {
  Promise.reject(err)
})

http.interceptors.response.use(response => {
  return response
}, err => {
  // Promise.reject(err)
  // console.log(err.response);

  /* 全局错误提示 */
  if (err.response.data.message) {
    Message({
      type: 'err',
      message: err.response.data.message
    })
  }
})

export default http